home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / or / or_rbits2or.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  2.7 KB  |  148 lines

  1. /* or_rbits2or.c: maps bits into OR */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_rbits2or.c,v 6.0 1991/12/18 20:23:08 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/or/RCS/or_rbits2or.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_rbits2or.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:08  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "or.h"
  19. #include "util.h"
  20. #include "table.h"
  21.  
  22. static Table    *tb_rfc2or = NULLTBL;
  23.  
  24. extern char     *rfc2or_tbl,
  25.         or_error[];
  26. extern OR_upperbound ortbl_88_ubs[];
  27.  
  28. /* ---------------------  Begin  Routines  -------------------------------- */
  29.  
  30.  
  31.  
  32. int or_domain2or (domain, or)
  33. char    *domain;
  34. OR_ptr    *or;
  35. {
  36.     OR_ptr      ptr, tmp;
  37.     char        buf[LINESIZE],
  38.     *p;
  39.  
  40.     PP_DBG (("Lib/or_domain2or (%s)", domain));
  41.  
  42.     if (tb_rfc2or == NULLTBL) {
  43.         if ((tb_rfc2or = tb_nm2struct (rfc2or_tbl)) == NULLTBL) {
  44.             PP_LOG (LLOG_EXCEPTIONS, ("Lib/or_rbits2or: rfc2or table NULL!"));
  45.             return NOTOK;
  46.         }
  47.     }
  48.  
  49.     for (p = domain; *p != '\0';) {
  50.         if (tb_k2val (tb_rfc2or, p, buf, TRUE) == OK)
  51.             break;
  52.         p = index (p, '.');
  53.         if (p == NULLCP)
  54.             break;
  55.         else
  56.             p++;
  57.     }
  58.  
  59.     if (p == NULLCP || *p == '\0') {
  60.         (void) sprintf (or_error,
  61.                 "No translation of '%s' to X400 address",
  62.                 domain);
  63.         return NOTOK;
  64.     }
  65.  
  66.     else {
  67.         *or = or_dmn2or (buf);
  68.         if (*or == NULLOR)
  69.             return or_lose ("format error '%s':'%s'",
  70.                     p, buf);
  71.  
  72.  
  73.  
  74.         if (p != domain) {
  75.             /* --- Must add more bits --- */
  76.             int         i;
  77.             int         tconst;
  78.             int         type;
  79.             int         oargc;
  80.             char        *oargv[50];
  81.  
  82.             p--;
  83.             *p = '\0';
  84.             oargc = sstr2arg (domain, 49, oargv, ".");
  85.  
  86.             if (*or != NULLOR) {
  87.                 ptr = *or;
  88.                 tconst = (or_lastpart (ptr)) -> or_type;
  89.             }
  90.             else
  91.                 tconst = OR_OU;
  92.  
  93.             for (i = oargc - 1; i >= 0; i--) {
  94.                 tconst++;
  95.                 if (tconst > OR_OU)
  96.                     type = OR_OU;
  97.                 else
  98.                     type = tconst;
  99.  
  100.                 if (!or_isdomsyntax (oargv[i]))
  101.                     return or_lose ("domain syntax error '%s'",
  102.                             oargv[i]);
  103.  
  104.                 ptr = or_new (type, NULLCP, oargv[i]);
  105.                 if (or_check_upper (ptr, ortbl_88_ubs) == NOTOK) {
  106.                     if (ptr)
  107.                         or_free(ptr);
  108.                     return NOTOK;
  109.                 }
  110.                 tmp = or_add (*or, ptr, FALSE);
  111.                 if (tmp == NULLOR)
  112.                     return NOTOK;
  113.                 else
  114.                     *or = tmp;
  115.  
  116.             }    /* --- end of for --- */
  117.  
  118.         }        /* --- end of if --- */
  119.  
  120.     }             /* --- end of else --- */
  121.     
  122.     return OK;
  123.  
  124. }
  125.     
  126. int or_local2or (local, or)
  127. char    *local;
  128. OR_ptr    *or;
  129. {
  130.     OR_ptr    ptr;
  131.     /* --- Add in the local bits --- */
  132.  
  133.     PP_DBG (("Lib/or_local2or (%s)", local));
  134.  
  135.     if ((ptr = or_std2or (local)) == NULLOR)
  136.         return or_lose ("local syntax error '%s'",
  137.                 local);
  138.  
  139.     *or = or_default_aux(ptr, *or);
  140.     /* try adding in loc_or for missing bits */
  141.     *or = or_default (*or);
  142.  
  143.     if (or_delete_atsigns (or) == NOTOK)
  144.         return NOTOK;
  145.     return OK;
  146. }
  147.  
  148.